<?php

namespace app\fuck\controller;

use cmf\controller\BaseController;
use plugins\fuck\lib\Kbzf;

/**
 * Class SheetController
 * @package app\fuck\controller
 * @adminMenuRoot(
 *     'name'   =>'课表转换',
 *     'action' =>'default',
 *     'parent' =>'',
 *     'display'=> true,
 *     'order'  => 30,
 *     'icon'   =>'th',
 *     'remark' =>'课表转换'
 * )
 */
class KbzfController extends BaseController
{

    /**
     * 通用课表转换
     * @adminMenu(
     *     'name'   => '通用课表转换',
     *     'parent' => 'default',
     *     'display'=> true,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '通用课表转换',
     *     'param'  => ''
     * )
     * @return mixed
     */
    public function kbzf()
    {

        return $this->fetch();
    }

    /**
     *  基础数据POST
     */
    public function post_jcsj()
    {
        $d = $this->request->param('jcsj/a', []);
        //var_dump($d);

        if (empty($d)) {
            $this->error("没有老师数据！");
        }
        if (empty($d['bjbh']) || empty($d['bjmc']) || empty($d['csbh']) || empty($d['csmc'])){
            $this->error('有空数据');
        }

        $m = new Kbzf();
        $ret = $m->save_jcsj($d);
        //var_dump($ls);

        if ($ret['code']) {
            $this->success($ret['msg'], '', $ret['data']);
        } else {
            $this->error($ret['msg'], '', $ret['data']);
        }
    }

    /**
     *  老师表POST
     */
    public function post_ls()
    {
        $ls = $this->request->param('ls/a', []);
        //var_dump($ls);

        if (empty($ls)) {
            $this->error("没有老师数据！");
        }
        if (empty($ls['lsxm']) || empty($ls['kcmc']) || empty($ls['bjmc'])){
            $this->error('有空数据');
        }

        $m = new Kbzf();
        $ret = $m->save_ls($ls);
        //var_dump($ls);

        if ($ret['code']) {
            $this->success($ret['msg'], '', $ret['data']);
        } else {
            $this->error($ret['msg'], '', $ret['data']);
        }
    }

    /**
     *  课表POST
     */
    public function post_kb()
    {
        $kb = $this->request->param('kb/a', []);        //课表是一行一行地取，否则数据太大有丢失Post数据情况
        //var_dump($kb);

        if (empty($kb)) {
            $this->error("没有课表数据！");
        }
        if (empty($kb['jc']) || empty($kb['kcmc']) || empty($kb['bjmc'])){
            $this->error('有空数据');
        }

        $m = new Kbzf();
        $res = $m->save_kb($kb);

        if ($res['code']) {
            $this->success($res['msg'], '', $res['data']);
        } else {
            $this->error($res['msg'], '', $res['data']);
        }
    }

}
